package com.acip.uuid.segment;

import com.acip.uuid.api.IdGenerator;
import com.acip.uuid.util.TableNameConvertUtil;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;

/**
 * @ClassName SegmentIdGenerator
 * @Description
 * @Author RayLiang
 * @Date 2022/11/28 15:42
 * @Version 1.0
 **/
@Service
public class SegmentIdGenerator implements IdGenerator {

    @Resource
    private BusinessCosIdSegmentCache businessCosIdSegment;

    @Override
    public Long getLongCosId(String businessId) {
        BusinessCosIdSegmentChain businessCosIdSegmentChain = businessCosIdSegment.getBusinessCosIdGenerator(businessId);
        return businessCosIdSegmentChain.getId();
    }

    @Override
    public BusinessCosIdSegmentChain getBusinessCosIdSegmentChain(String businessId) {
        return businessCosIdSegment.getBusinessCosIdGenerator(businessId);
    }

    @Override
    public BusinessCosIdSegmentChain getBusinessCosIdSegmentChain(Class cls) {
        String tableName = TableNameConvertUtil.toSymbolCase(cls.getSimpleName());
        return businessCosIdSegment.getBusinessCosIdGenerator(tableName);
    }
}
